package net.caixiaomi.info.Lottery.adapter;

import android.support.annotation.Nullable;
import android.text.Html;
import android.widget.LinearLayout;
import android.widget.TextView;

import net.caixiaomi.info.Lottery.model.LotteryBettingEntity;
import net.caixiaomi.info.R;
import net.caixiaomi.info.base.quickadapter.BaseMultiItemQuickAdapter;
import net.caixiaomi.info.base.quickadapter.BaseViewHolder;
import net.caixiaomi.info.base.quickadapter.entity.MultiItemEntity;
import net.caixiaomi.info.util.Constants;

import java.util.List;

/**
 * Created by suntian on 2018/8/15.
 */

public class LotteryBettingAdapter extends BaseMultiItemQuickAdapter<MultiItemEntity,BaseViewHolder> {

    private int mTrebleNum=1;
    private boolean mSelected;
    private boolean mAddChips=false;

    public LotteryBettingAdapter(@Nullable List<MultiItemEntity> data) {
        super(data);
        addItemType(Constants.ITEM_LOTTERY_BETTING, R.layout.lottery_betting_item_layout);
        addItemType(Constants.ITEM_LOTTERY_BEETTING_MORE, R.layout.view_service_protocol);
    }

    @Override
    protected void convert(BaseViewHolder helper, MultiItemEntity item) {
        try {
            switch (item.getItemType()) {
                case Constants.ITEM_LOTTERY_BETTING:
                    bindView(helper, item);
                    break;
                case Constants.ITEM_LOTTERY_BEETTING_MORE:
                    bindFooterView(helper, item);
                    break;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void bindView(BaseViewHolder helper, MultiItemEntity item){
        String des="";

        int index=0;
//            des="<html><body>请至少选择<font color='red'>5</font>个红球 <font color='blue'>2</font>个蓝球 </body></html>";
        LotteryBettingEntity entity= (LotteryBettingEntity) item;
        if(entity.getStatus()==0||entity.getStatus()==1){
            String befores="";
            String afters="";
            for(int i=0;i<entity.getmBefores().size();i++){
                befores=befores+"  "+entity.getmBefores().get(i);
                if(index==7){
                    index=0;
                    befores=befores+"<br>";
                }else {
                    index++;
                }
            }
            for(int i=0;i<entity.getmAfters().size();i++){
                afters=afters+"  "+entity.getmAfters().get(i);
                if(index==7){
                    index=0;
                    afters=afters+"<br>";
                }else {
                    index++;
                }
            }
            afters=afters+"<br>";
            des="<html><body><font color='red'>"+befores+"</font><font color='blue'>"+afters+"</font>";

        }else{
            String beforeDans="";
            String afterDans="";
            String beforeTuos="";
            String afterTuos="";
            for(int i=0;i<entity.getmBeforeDans().size();i++){
                beforeDans=beforeDans+"  "+entity.getmBeforeDans().get(i);
                if(index==7){
                    index=0;
                    beforeDans=beforeDans+"<br>";
                }else {
                    index++;
                }
            }
            if(!beforeDans.equals("")){
                beforeDans=beforeDans+"  -";
            }
            index++;
            for(int i=0;i<entity.getmBeforeTuos().size();i++){
                beforeTuos=beforeTuos+"  "+entity.getmBeforeTuos().get(i);
                if(index==7){
                    index=0;
                    beforeTuos=beforeTuos+"<br>";
                }else {
                    index++;
                }
            }
            if(!beforeTuos.equals("")){
                beforeTuos=beforeTuos+"  -";
            }
            index++;
            for(int i=0;i<entity.getmAfterDans().size();i++){
                afterDans=afterDans+"  "+entity.getmAfterDans().get(i);
                if(index==7){
                    index=0;
                    afterDans=afterDans+"<br>";
                }else {
                    index++;
                }
            }
            if(!afterDans.equals("")){
                afterDans=afterDans+"  -";
            }
            index++;
            for(int i=0;i<entity.getmAfterTuos().size();i++){
                afterTuos=afterTuos+"  "+entity.getmAfterTuos().get(i);
                if(index==7){
                    index=0;
                    afterTuos=afterTuos+"<br>";
                }else {
                    index++;
                }
            }
            afterTuos=afterTuos+"<br>";
            des="<html><body><font color='red'>"+beforeDans+beforeTuos+"</font><font color='blue'>"+afterDans+afterTuos+"</font>";
        }
        des="<big>"+des+"</big>";
        long lMoney=entity.getMoney();
        lMoney= (long) (lMoney*mTrebleNum*(mAddChips?1.5:1));
        switch (entity.getStatus()){
            case 0:
                des="<small>"+des+"单式  "+entity.getChips()+"注  "+mTrebleNum+"倍  "+lMoney+".00元"+"</small>";
                break;
            case 1:
                des="<small>"+des+"复式  "+entity.getChips()+"注  "+mTrebleNum+"倍  "+lMoney+".00元"+"</small>";
                break;
            case 2:
                des="<small>"+des+"胆拖  "+entity.getChips()+"注  "+mTrebleNum+"倍  "+lMoney+".00元"+"</small>";
                break;
        }
        TextView tv=helper.getView(R.id.lottery_betting_item_tv);
        tv.setText(Html.fromHtml(des));
        helper.addOnClickListener(R.id.lottery_bet_ite_go);
        helper.addOnClickListener(R.id.lottery_bet_ite_delete);
//        helper.setTag(R.id.lottery_bet_ite_go,"go");
//        helper.setTag(R.id.lottery_bet_ite_delete,"delete");
    }

    private void bindFooterView(BaseViewHolder helper, MultiItemEntity item){

        LinearLayout mBtnSelected = helper.getView(R.id.btn_selected);
        helper.addOnClickListener(R.id.btn_selected);
        helper.addOnClickListener(R.id.btn_protocol);
        mBtnSelected.setSelected(mSelected);
    }

    public void setmTrebleNum(int mTrebleNum){
        this.mTrebleNum=mTrebleNum;
        notifyDataSetChanged();
    }

    public void setChips(boolean chips){
        mAddChips=chips;
        notifyDataSetChanged();
    }

    public void setSelected(boolean select){
        mSelected=select;
        notifyDataSetChanged();
    }

//    public interface CallBack{
//        public void setSelected(boolean select);
//    }
}
